package com.itheima.day14.day14work1;

import java.util.concurrent.Callable;

public class WangDian implements Callable<Integer> {
    private  Water w;
    public WangDian(Water w) {
        this.w=w;
    }

    @Override
    public Integer call() throws Exception {
        int count=0;

       while (true) {
           synchronized (w.getObj()) {
               int num = w.getNum();
               if (num<=0){
                   break;
               }
               Thread.sleep(100);
               count++;
               System.out.println("网店卖出一杯水，剩余" + (--num));
               w.setNum(num);

           }
       }

        return count;
    }
}
